const axios = require('axios');

const BASE_URL = 'http://localhost:4000/api';

async function debugLogin() {
  console.log('🔐 调试登录接口...');
  console.log('   请求URL:', `${BASE_URL}/auth/login`);
  console.log('   请求数据:', { username: 'admin', password: 'admin123' });
  
  try {
    const response = await axios.post(`${BASE_URL}/auth/login`, {
      username: 'admin',
      password: 'admin123'
    });
    
    console.log('✅ 登录成功');
    console.log('   响应状态:', response.status);
    console.log('   响应数据:', response.data);
    
  } catch (error) {
    console.log('❌ 登录失败');
    console.log('   错误类型:', error.constructor.name);
    console.log('   错误消息:', error.message);
    
    if (error.response) {
      console.log('   响应状态:', error.response.status);
      console.log('   响应数据:', error.response.data);
      console.log('   响应头:', error.response.headers);
    } else if (error.request) {
      console.log('   请求已发送但无响应');
      console.log('   请求配置:', error.request);
    } else {
      console.log('   请求配置错误:', error.config);
    }
  }
}

debugLogin();
